﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Basic;
using Basic.Part2;
using Basic.第一章;

namespace DesignPatternDemoTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod()//手动实现依赖注入的单元测试
        {
            var timeprovider = new Assembler().Create<ITimerProvider>();
            Assert.IsNotNull(timeprovider);//确认可以正常获取抽象类型实例
            var client = new ClientConstructor(timeprovider);//在构造函数中注入
            var client1 = new ClientSetter { Timeprovider = timeprovider };//在setter中注入
        }

        [TestMethod]
        public void TypeCreatorTest()//手动实现替换掉new()的方式来实例化一个类
        {
            //Dictionary<Type, Type> dic = new Dictionary<Type, Type>();//保存"抽象类型/实体类型"对应关系的字典 一般通过配置文件获取
            //dic.Add(typeof(IObjectBuilder), typeof(TypeCreator));

            IObjectBuilder creator = new TypeCreator();
            Assert.IsInstanceOfType(creator.BuildUp<ClientSetter>(), typeof(ClientSetter));
        }
        
    }
}
